package io.osw.modules.approve.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.Date;
import io.osw.common.validator.ValidatorUtils;
import io.osw.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import io.osw.modules.approve.entity.TblApproveFlowStatusEntity;
import io.osw.modules.approve.service.TblApproveFlowStatusService;
import io.osw.common.utils.PageUtils;
import io.osw.common.utils.R;



/**
 * 审批明细表
 *
 * @author guxiaoguang
 * @email xuebai864627555@gmail.com
 * @date 2019-01-10 21:26:33
 */
@RestController
@RequestMapping("approve/tblapproveflowstatus")
public class TblApproveFlowStatusController extends AbstractController {
    @Autowired
    private TblApproveFlowStatusService tblApproveFlowStatusService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("approve:tblapproveflowstatus:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tblApproveFlowStatusService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{fstId}")
    @RequiresPermissions("approve:tblapproveflowstatus:info")
    public R info(@PathVariable("fstId") Long fstId){
        TblApproveFlowStatusEntity tblApproveFlowStatus = tblApproveFlowStatusService.selectById(fstId);

        return R.ok().put("tblApproveFlowStatus", tblApproveFlowStatus);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("approve:tblapproveflowstatus:save")
    public R save(@RequestBody TblApproveFlowStatusEntity tblApproveFlowStatus){
        tblApproveFlowStatus.setCreateTime(new Date());
        tblApproveFlowStatus.setCreateBy(getUser().getUserId());
        tblApproveFlowStatusService.insert(tblApproveFlowStatus);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("approve:tblapproveflowstatus:update")
    public R update(@RequestBody TblApproveFlowStatusEntity tblApproveFlowStatus){
        ValidatorUtils.validateEntity(tblApproveFlowStatus);
        tblApproveFlowStatus.setUpdateTime(new Date());
        tblApproveFlowStatus.setUpdateBy(getUser().getUserId());
        tblApproveFlowStatusService.updateAllColumnById(tblApproveFlowStatus);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("approve:tblapproveflowstatus:delete")
    public R delete(@RequestBody Long[] fstIds){
        tblApproveFlowStatusService.deleteBatchIds(Arrays.asList(fstIds));

        return R.ok();
    }

}
